{extend name="public/base"}

{block name="title"}
签到
{/block}

{block name="style"}
{css href="/static/wechat/css/singnin.css" /}
{/block}
{block name="body"}
<div class="pageControl orderDetails">
    <div class="msui_nav msui_navTop" style="border-bottom: 1px solid #cccccc;">
        <a class="msui_navTop-back" href="javascript:history.back();"><i class="micon-back"></i></a>
        <h1 class="msui_navTop-title">签到</h1>
    </div>

    <div class="qian_div">
        <div class="day_div">
            <p class="fs07">已经连续签到{$registration.days|default=0}天</p>
            <a class="fs07 md_corlor" href="{:url('what_is_the_integral')}">什么是摩豆<i class="mdbg"></i></a>
        </div>
        <div class="qiandao_div">
            <div class="md_nubdiv">
                <p class="md_nub"><i>{$registration.point|default=0}</i>&nbsp;<span>摩豆(颗)</span></p>
            </div>
            <div class="btn_div">
            </div>
            <div class="open-popup popqd1" data-target="#Popqd1" style="display: none;"></div>
            <div class="open-popup popqd2" data-target="#Popqd2" style="display: none;"></div>
        </div>
    </div>
    <!--签到明细-->
    <div class="qdmx_div">
        <p class="fs07">签到明细</p>
    </div>
    <ul class="qiandao_ul">
    </ul>

    <!--签到弹窗-->
    <!--<div id="Popup2" class="weui-popup__container popup-bottom">-->

    <div id="Popqd1" class="weui-popup__container">
        <div class="weui-popup__overlay"></div>
        <div class="weui-popup__modal touming">
            <div class="tanchuang_div" >
                <div>
                    <p class="fs08 qd_success">恭喜签到成功</p>
                </div>

                <div>
                    <div class="solid_mid">
                        <span class="solid_sp"></span>
                        <p class="fs065 lxqd lxqd1">连续签到<span>0</span>天</p>
                        <span class="solid_sp"></span>
                    </div>

                    <span class="fs12 magicB">摩豆+<span>10</span></span>
                    <p class="fs07 lxqd lxqd2">明天继续签到可获得<span>0</span>摩豆</p>
                    <button class="close-popup qdbtn fs08" id="zhidaole">知道了</button>
                </div>
            </div>
        </div>
    </div>

    <div id="Popqd2" class="weui-popup__container">
        <div class="weui-popup__overlay"></div>
        <div class="weui-popup__modal touming">
            <div class="tanchuang_div2" >
                <span class="fs08">提示</span>
                <h1 class="fs085 magicB">今天已经签到过了，明天再来吧</h1>
                <button class="close-popup qdbtn fs08">知道了</button>

            </div>
        </div>
    </div>
</div>

<!-- loading toast -->
<div id="loadingToast" style="display:none;">
    <div class="weui-mask_transparent"></div>
    <div class="weui-toast" style="opacity: 1; visibility: visible;">
        <i class="weui-loading weui-icon_toast"></i>
        <p class="weui-toast__content">正在签到</p>
    </div>
</div>
{/block}
{block name="javascript"}
<script>
$(function () {
    var obj = {
        'is_more' : true,
        'page' : 1,
        'action' : 'append'
    };
    // 签到明细
    get_sign_in_list();
    $(document).on('click', '#no_qd',function () {
        $('#loadingToast').fadeIn(100);
        var _this = $(this);
        if (_this.hasClass('yqd')) {
            return false;
        }
        $.get("{:url('save_registration')}", function (msg) {
            if (msg.code == 200) {
                $(".btn_div").addClass('yqd').html('<button id="qd_over" style="display:block;">已签到</button>');
                $('#loadingToast').fadeOut(100);
                $(".lxqd1 span").text(msg.data.days);
                $(".magicB span").text(msg.data.num);
                $(".md_nub i").text(parseInt($(".md_nub i").text()) + msg.data.num);
                if (msg.data.days == 7) {
                    $(".lxqd2").text('连续签到一周，每周一重置累积天数');
                } else {
                    $(".lxqd2 span").text(msg.data.tomorrow_num);
                }
                $('.popqd1').click();

                // 获取签到明细
                obj.page = 1;
                obj.action = 'html';
                get_sign_in_list();
            } else {
                alert('失败！')
            }
        }, 'json')
    });

    $(document).on('click', '#qd_over',function () {
        $('.popqd2').click();
    });

    $.get("{:url('check_registration')}", function (msg) {
        if (msg.code != 200) {
            $(".btn_div").addClass('yqd').html('<button id="qd_over" style="display:block;">已签到</button>');
        } else {
            $(".btn_div").html('<button id="no_qd">签到</button>');
        }
    });


    $(window).scroll( function() {
        if (($(document).height() - $(this).scrollTop() - $(this).height()<50) && obj.is_more){
            obj.action = 'append';
            get_sign_in_list();
        }
    });

    function get_sign_in_list() {
        obj.is_more = false;
        $.ajax({
            type : 'POST',
            url : '{:url("get_sign_in_list")}?page=' + obj.page,
            dataType : 'json',
            success : function (msg) {
                var data = msg.data.data; // 数据
                var len = data.length; //
                var html = [];
                for (var i = 0; i < len; i++) {
                    var h = '<li>' +
                            '<div class="qd_type">' +
                            '<p class="fs10">+'+ data[i].num +'</p>' +
                            '<span class="fs07 qdcolor">每天签到任务</span>' +
                            '</div>' +
                            '<div class="time_div">' +
                            '<span class="fs07 qdcolor">'+ getLocalTime(data[i].add_time, 1) +'</span>' +
                            '</div>' +
                            '</li>' +
                            '<div class="solid"></div>';
                    html.push(h)
                }
                if (obj.action == 'html') {
                    $(".qiandao_ul").html(html.join(''));
                } else {
                    $(".qiandao_ul").append(html.join(''));
                }

                // 计算是否还有更多数据
                if ((msg.data.total - (msg.data.current_page * msg.data.per_page)) > 0) {
                    obj.is_more = true;
                }
                obj.page++;
            }
        });
    }
});
</script>
{/block}